<?php/*  PHP version 5  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220*/


use inc_application\link\ArticleLink;

class lib_tags {

	public static function call_tags($parameter, $filename = 'tags', $outHTML = null) {
		$espcms_lib_template = espcms_web_template();
		$espcms_lib_template->libfile = true;
		$para = espcms_array_getvalue($parameter);
		$limit = espcms_ismatches($para['max']) && $para['max'] ? $para['max'] : 20;
		$lng = espcms_lancode();
		$db_where = " AND isclass=1 AND lng='$lng'";
		if (espcms_ismatches($para['mid']) && $para['mid']) {
			$db_where .= " AND mid=" . $para['mid'];
		}
		if (espcms_ismatches($para['tid']) && $para['tid']) {
			$db_where .= " AND tid=" . $para['tid'];
		}
		if (espcms_ismatches($para['istop'])) {
			$db_where .= " AND istop=" . $para['istop'];
		}
		if (espcms_ismatches($para['islink'])) {
			$db_where .= " AND islink=" . $para['islink'];
		}
		$db_table = ESPCMS_DB_PREFIX . 'keylink';
		$talbe_field_array = espcms_field_out($db_table);
		$list_array = espcms_db_list_array($db_table, $talbe_field_array, $db_where, 'pid,kid DESC', '0,' . $limit);
		if (is_array($list_array)) {
			foreach ($list_array as $key => $value) {
				$list_array[$key]['title'] = $value['keywordname'];
				$list_array[$key]['link'] = $value['islink'] ? $value['linkurl'] : ArticleLink::tags_link($value);
			}
		}
		$espcms_lib_template->into('para', $para);
		$espcms_lib_template->into('tags_array', $list_array);
		$espcms_lib_template->into('array', $list_array);
		if (!empty($outHTML)) {
			$output = $espcms_lib_template->fetch(null, null, $outHTML);
		} else {
			$output = $espcms_lib_template->fetch('lib/' . $filename);
		}
		return $output;
	}

}
